package com.kumz.SpringMVC.mapper;

import com.kumz.SpringMVC.pojo.User;

/**
 * Author: Yunz
 * E-mail: 1603754314@qq.com
 * Date: 2022/12/10
 */
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper{
    @Select("select * from user where username=#{username} AND password=#{password} AND user_lock_status!='1'")
    @Results(id = "userMap",value = {
            //id字段默认为false，表示不是主键
            //column表示数据库表字段，property表示实体类属性名。
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "user_lock_time",property = "lock_time"),
            @Result(column = "user_lock_status",property = "lock_status"),
            @Result(column = "count",property = "count")
    })
    User login(User user);//登录模块方法

    @Insert("insert into user(username,password) values (#{username},#{password})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addUser(User user);//添加用户方法

    @Delete("delete from user where id=#{userid}")
    int deleteUserByName(int id);//删除用户方法

    @Update("update user set username=#{username},password=#{password},user_lock_time=#{lock_time},user_lock_status=#{lock_status},count=#{count} where id=#{id}")
    int updateUser(User user);//更新用户方法

    @Select("select * from user where id=#{id}")
    @Results(id = "selectUserById",value = {
            //id字段默认为false，表示不是主键
            //column表示数据库表字段，property表示实体类属性名。
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "user_lock_time",property = "lock_time"),
            @Result(column = "user_lock_status",property = "lock_status"),
            @Result(column = "count",property = "count")
    })
    User selectUserById(int id);//根据id查询用户

    @Select("select * from user")
    @Results(id = "selectAllUser",value = {
            //id字段默认为false，表示不是主键
            //column表示数据库表字段，property表示实体类属性名。
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "user_lock_time",property = "lock_time"),
            @Result(column = "user_lock_status",property = "lock_status"),
            @Result(column = "count",property = "count")
    })
    List<User> selectAllUser();//查询所有用户

    @Select("select * from user where username LIKE #{username}")
    @Results(id = "selectUserByName",value = {
            //id字段默认为false，表示不是主键
            //column表示数据库表字段，property表示实体类属性名。
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "user_lock_time",property = "lock_time"),
            @Result(column = "user_lock_status",property = "lock_status"),
            @Result(column = "count",property = "count")
    })
    User selectUserByName(String username);//根据用户名查找用户-模糊查询 LIKE

}
